package com.zrt.bookstore3.Dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zrt.bookstore3.Domain.Book;
import com.zrt.bookstore3.Domain.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookDao extends BaseMapper<Book> {

    @Select("select * from my_bookstore.book ,my_bookstore.b_o  where my_bookstore.book.id = b_o.book_id and my_bookstore.b_o.order_id=#{oid}")
            List<Book> findByOid(int oid);



    @Select("select * from book")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "type",column = "type"),
            @Result(property = "price",column = "price"),
            @Result(property = "orderList",column = "id",
                    javaType = List.class,
                    many = @Many(select =
                            "com.zrt.bookstore3.Dao.OrderDao.findByBookId"))
    })
    List<Book> findAllUserAndOrder();


    @Select("select * from book where id = #{id}")
    Book selectById(int id);

    List<Book> selectByCondition(Book book);

    @Select("select * from book")
    List<Book> selectAll();

    @Select("select * from book where category_id = #{cid}")
    List<Book> searchAllBooksByType(int cid);
}
